#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

class Solution
{
public:
    int candy(vector<int> &ratings)
    {
        vector<int> raise(ratings.size(), 1);
        vector<int> fall(ratings.size(), 1);
        for(int i = 1; i < ratings.size(); i++){
            if(ratings[i] > ratings[i - 1]){
                raise[i] = raise[i - 1] + 1;
            }
        }
        for(int i = ratings.size() - 2; i >= 0; i--){
            if(ratings[i] > ratings[i + 1]){
                fall[i] = fall[i + 1] + 1;
            }
        }
        vector<int> m(ratings.size());
        for(int i = 0; i < ratings.size(); i++){
            m[i] = max(raise[i], fall[i]);
        }
        return accumulate(m.begin(), m.end(), 0);
    }
};

int main()
{
    cout << "Code135" << endl;
    Solution s;
    vector<int> ratings = {1, 0, 2};
    cout << s.candy(ratings) << endl;
    return 0;
}